package com.bolt.report.business.test;

import com.bolt.common.collection.IteratorUtil;
import com.bolt.common.utils.RandomUtil;
import com.bolt.report.engine.DataProvider;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("testReportDataProvider")
public class ReportDataProvider implements DataProvider<ProductBean> {

    List<ProductBean> datas = new ArrayList<>();

    @Override
    public List<ProductBean> loadData(Map<String,Object> param) {
        String[] product = new String[]{"香焦", "苹果", "荔枝", "香梨", "葡萄", "提子"};
        String[] area = new String[]{"河南", "河北", "湖南", "四川"};
        if (IteratorUtil.isEmpty(datas)) {
            for (int i = 0; i < 92; i++) {
                ProductBean productBean = new ProductBean();
                productBean.setProNum(String.valueOf(i));
                productBean.setArea(area[RandomUtil.randomInt(0, 3)]);
                productBean.setProduct(product[RandomUtil.randomInt(0, 5)]);
                productBean.setQuantity(new BigDecimal(RandomUtil.randomInt(1, 100)));
                productBean.setPrice(new BigDecimal(RandomUtil.randomInt(20, 100)));
                datas.add(productBean);
            }
        }
        return datas;
    }
}